##开启事务
BEGIN;
SET NAMES utf8mb4;

-- ------------------------> 正式开始写 SQL 语句 <------------------------

-- ----------------------------
-- 基础消费项目
-- ----------------------------
DROP TABLE IF EXISTS `hair_salon`.`basic_item`;
CREATE TABLE `hair_salon`.`basic_item`
(
    `id`          varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci  NOT NULL COMMENT '数据ID',
    `shop_id`     varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci  NULL COMMENT '店铺ID',
    `base_name`   varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci  NULL COMMENT '基础项目名称',
    `ope_user_id` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci  NULL COMMENT '默认操作用户ID',
    `sort_number` int                                                           NULL COMMENT '顺序编号(越小越靠前)',
    `remark`      varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '备注',
    `is_deleted`  tinyint(1)                                                    NOT NULL DEFAULT 0 COMMENT '逻辑删除：1(已删除) 0(未删除)',
    `create_time` datetime                                                      NULL COMMENT '创建时间',
    `update_time` datetime                                                      NULL COMMENT '修改时间',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_general_ci COMMENT = '基础项目表'
  ROW_FORMAT = Dynamic;

-- 消费账单新增操作用户ID
ALTER TABLE `hair_salon`.`expense_bill`
    ADD COLUMN `operate_user_id` varchar(50) NULL COMMENT '操作用户ID' AFTER `final_price`;

DROP TABLE IF EXISTS `hair_salon`.`item_to_basic`;
CREATE TABLE `hair_salon`.`item_to_basic`
(
    `id`          varchar(50) NOT NULL COMMENT '数据ID',
    `item_id`     varchar(50) NOT NULL COMMENT '消费单ID',
    `basic_id`    varchar(50) NOT NULL COMMENT '基础项目ID',
    `is_deleted`  tinyint(1)  NOT NULL DEFAULT 0 COMMENT '逻辑删除：1(已删除) 0(未删除)',
    `create_time` datetime    NULL COMMENT '创建时间',
    `update_time` datetime    NULL COMMENT '修改时间',
    PRIMARY KEY (`id`)
) COMMENT = '消费单关联基础项目表';

DROP TABLE IF EXISTS `hair_salon`.`bill_basic_item`;
CREATE TABLE `hair_salon`.`bill_basic_item`
(
    `id`          varchar(50)  NOT NULL COMMENT '数据ID',
    `bill_id`     varchar(50)  NOT NULL COMMENT '账单ID',
    `basic_id`    varchar(50)  NULL COMMENT '基础项目ID',
    `basic_name`  varchar(255) NULL COMMENT '基础项目名称',
    `ope_user_id` varchar(50)  NULL COMMENT '完成操作用户ID',
    `remark`      varchar(200) NULL COMMENT '备注',
    `is_deleted`  tinyint(1)   NOT NULL DEFAULT 0 COMMENT '逻辑删除：1(已删除) 0(未删除)',
    `create_time` datetime     NULL COMMENT '创建时间',
    `update_time` datetime     NULL COMMENT '修改时间',
    PRIMARY KEY (`id`)
) COMMENT = '账单基础项目表';

-- 充值账单新增操作用户ID
ALTER TABLE `hair_salon`.`top_up_bill`
    ADD COLUMN `operate_user_id` varchar(50) NULL COMMENT '操作用户ID' AFTER `bill_time`;

-- ------------------------> 正式结束写 SQL 语句 <------------------------
##提交事务
COMMIT;

## 如遇错误, 执行以下sql
## ROLLBACK;